/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package user;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.sql.Date;
import java.util.List;
import javax.persistence.*;
import transactions.LateCharge;
import transactions.Rental;
import transactions.Reservation;

/**
 *
 * @author Nacer Khalil
 */
@Entity
@Table(name="customer")
@NamedQueries({
@NamedQuery(name="findCustomer", query="select a from Customer a where firstname=:name "),
@NamedQuery(name="getAllCustomers", query="select a from Customer a")
})
public class Customer extends User{
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    
    private Date registrationDate;
    
    @OneToMany
    @JoinColumn(name = "cus_id", referencedColumnName = "id")
    private List<Rental> rentals;
    
    @OneToMany
    @JoinColumn(name = "cus_id", referencedColumnName = "id")
    private List<Reservation> reservations;
    
    @OneToMany
    @JoinColumn(name = "cus_id", referencedColumnName = "id")
    private List<LateCharge> charges;
    
    
    public Customer() {
        super();
    }
    

    public Customer(String firstName, String lastName, String address, String phoneNumber, Date registrationDate) {
        super(firstName, lastName, address, phoneNumber);
        this.registrationDate = registrationDate;
    }
    
    
    /**
     * @return the registrationDate
     */
    public Date getRegistrationDate() {
        return registrationDate;
    }

    /**
     * @return the rentals
     */
    public List<Rental> getRentals() {
        return rentals;
    }

    /**
     * @return the reservations
     */
    public List<Reservation> getReservations() {
        return reservations;
    }

    /**
     * @return the charges
     */
    public List<LateCharge> getCharges() {
        return charges;
    }

    /**
     * @param registrationDate the registrationDate to set
     */
    public void setRegistrationDate(Date registrationDate) {
        Date oldRegistrationDate = this.registrationDate;
        this.registrationDate = registrationDate;
        changeSupport.firePropertyChange("registrationDate", oldRegistrationDate, registrationDate);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        if (this.registrationDate != other.registrationDate && (this.registrationDate == null || !this.registrationDate.equals(other.registrationDate))) {
            return false;
        }
        if (this.rentals != other.rentals && (this.rentals == null || !this.rentals.equals(other.rentals))) {
            return false;
        }
        if (this.reservations != other.reservations && (this.reservations == null || !this.reservations.equals(other.reservations))) {
            return false;
        }
        if (this.charges != other.charges && (this.charges == null || !this.charges.equals(other.charges))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    
   
    
    
}
